﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ManageReportVer1.Models;
using System.Web.Security;

namespace ManageReportVer1
{
    public class CustomRoleProvider : RoleProvider
    {
       
        public override string[] GetRolesForUser(string userID)
        {

            try
            {
                TimeSpan temp = FormsAuthentication.Timeout;
                DBDataContext dbData = new DBDataContext();
                var userName = from s in dbData.Users where (s.UserName == userID) select s;

                int userId = int.Parse(userName.First().UserId.ToString());
               // int userId = int.Parse(userID);
                var users = from s in dbData.Users where (s.UserId==userId) select s;
                if (users != null)
                {
                    if (users.First().RoleId == 1)
                        return new string[] { "User" };
                    else if (users.First().RoleId == 2)
                        return new string[] { "Admin" };
                    else if (users.First().RoleId == 3)
                        return new string[] { "Operator" };
                }
                
            }
            catch (Exception ex) { }
            return new String[] { };
        }
       
        public override bool IsUserInRole(string userID, string roleName)
        {
            try
            {
                
            }
            catch (Exception ex) { }
            return false;
        }
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }



        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}